package com.tour.modules.web.controller;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.tour.common.utils.PageUtils;
import com.tour.common.utils.Query;
import com.tour.common.utils.R;
import com.tour.modules.sys.shiro.ShiroUtils;
import com.tour.modules.web.entity.TWorkOrderContentEntity;
import com.tour.modules.web.service.TWorkOrderContentService;

/**
 * 留言对话内容表
 * 
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2018-01-06 22:44:15
 */
@RestController
@RequestMapping("tworkordercontent")
public class TWorkOrderContentController {
	@Autowired
	private TWorkOrderContentService tWorkOrderContentService;

	/**
	 * 列表
	 */
	@RequestMapping("/list")
	public R list(@RequestParam Map<String, Object> params) {
		// 查询列表数据
		Query query = new Query(params);

		List<TWorkOrderContentEntity> tWorkOrderContentList = tWorkOrderContentService.queryList(query);
		int total = tWorkOrderContentService.queryTotal(query);

		PageUtils pageUtil = new PageUtils(tWorkOrderContentList, total, query.getLimit(), query.getPage());

		return R.ok().put("page", pageUtil);
	}

	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	public R info(@PathVariable("id") Long id) {
		TWorkOrderContentEntity tWorkOrderContent = tWorkOrderContentService.queryObject(id);

		return R.ok().put("tWorkOrderContent", tWorkOrderContent);
	}

	/**
	 * 保存
	 */
	@RequestMapping("/save")
	public R save(@RequestBody TWorkOrderContentEntity tWorkOrderContent) {
		tWorkOrderContentService.save(tWorkOrderContent);

		return R.ok();
	}

	/**
	 * 修改
	 */
	@RequestMapping("/update")
	public R update(@RequestBody TWorkOrderContentEntity tWorkOrderContent) {
		tWorkOrderContentService.update(tWorkOrderContent);

		return R.ok();
	}

	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	public R delete(@RequestBody Long[] ids) {
		tWorkOrderContentService.deleteBatch(ids);

		return R.ok();
	}

	/**
	 * 查询某用户留言的所有内容
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping("/ListByWorkOrderId/{id}")
	public R ListByWorkOrderId(@PathVariable("id") Long id) {
		List<TWorkOrderContentEntity> tWorkOrderContentEntity = tWorkOrderContentService.queryListByTWorkOrderId(id);
		return R.ok().put("tWorkOrderContentEntity", tWorkOrderContentEntity);
	}

	/**
	 * 
	 */
	@RequestMapping("/saveAdmin")
	public R saveAdmin(@RequestBody TWorkOrderContentEntity tWorkOrderContent) {
		tWorkOrderContent.setCreateTime(new Date());
		tWorkOrderContent.setUserId(ShiroUtils.getUserId());
		tWorkOrderContent.setStatue(1);
		tWorkOrderContentService.save(tWorkOrderContent);
		return R.ok();

	}
}
